package day3;

import java.util.Scanner;

import org.junit.Test;
import org.omg.CORBA.PUBLIC_MEMBER;

/*
 * 作业1：
 * int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
 * 求出上面数组中0-9分别出现的次数
 * 
 */

public class Count {
	public static void main(String[] args) {
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] countarray=new int[10];
		for(int i = 0;i < score.length; i++) {
			switch(score[i]) {
			case 0:
				countarray[0] += 1;
				break;
			case 1:
				countarray[1] += 1;
				break;
			case 2:
				countarray[2] += 1;
				break;
			case 3:
				countarray[3] += 1;
				break;
			case 4:
				countarray[4] += 1;
				break;
			case 5:
				countarray[5] += 1;
				break;
			case 6:
				countarray[6] += 1;
				break;
			case 7:
				countarray[7] += 1;
				break;
			case 8:
				countarray[8] += 1;
				break;
			case 9:
				countarray[9] += 1;
				break;
			default:
				System.out.println("default" + score[i]);
				break;
			}
		}
		for(int i = 0; i < countarray.length; i ++) {
			System.out.println(i + "出现的次数为：" + countarray[i]);
		}
	}
	/*
	 * 作业2：
	 * int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	 * 要求求出其中的奇数个数和偶数个数。
	 */	
	@Test
	public void test() {
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int evenCount = 0;//偶数个数
		int oddCount = 0;//奇数个数
		for (int i = 0; i < score.length; i++) {
			if(score[i] % 2 == 0) {
				evenCount += 1;
			}
			else {
				oddCount +=1;
			}
		}
		System.out.println("奇数个数为:" + oddCount);
		System.out.println("偶数个数为:" + evenCount);
	}
	/*
	 * 作业3
	 * 输入一组学生的成绩，然后计算他们的平均值.
	 * 
	 */
	@Test
	public void test1() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生人数：");
		int a = scanner.nextInt();
		double []scorearray = new double[a];
		double averagescore ;
		double sumscore = 0;
		for(int i = 0;i < scorearray.length; i++) {
			System.out.println("请输入第" + (i + 1) + "个学生成绩：");
			double score = scanner.nextDouble();
			scorearray[i] = score;
			sumscore += scorearray[i];
		}
		averagescore = sumscore / 5 ;
		System.out.println("平均成绩为：" + averagescore);
	}
	/*作业16
	 * 一个5位数，判断它是不是回文数。即12321是回文数
	 * ，个位与万位相同，十位与千位相同。
	 */	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个五位数：");
		String string = scanner.nextLine();
		char []a = string.toCharArray();
		if(a[0] == a[4] && a[1] == a[3]) {
			for(int i = 0;i < a.length; i++) {
				System.out.print(a[i]);
			}
			System.out.println("是回文数。");
		}
		else {
			System.out.println("不是回文数。");
		}
	}
	/*
	 * 
	 * 
	 * 作业17
	 * 输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数
	 * 
	 */
	@Test
	public void test3() {
		int num = 0;       //数字个数
		int letter = 0;    //字母个数
		int space = 0;     //空格个数
		int others = 0;    //其他个数
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一行字符：");
		String string = scanner.nextLine();
		char []a = string.toCharArray();
		for (int i = 0; i < a.length; i++) {
			if (a[i] >= '0' && a[i] <= '9') {
				num++;
			}
			else if(a[i] >= 'A' && a[i] <= 'Z' || a[i] >= 'a' && a[i] <= 'z') {
				letter++;
			}else if (a[i] == ' ') {
				space++;
			}
			else {
				others++;
			}
		}
		System.out.println("字符中，英文字母、空格、数字和其他字符的个数分别为：");
		System.out.print(letter + " " + space + " " + num + " " + others);
	}
	
	/*
	 * 
	 * 作业18
	 * 输入三个整数x,y,z，请把这三个数由小到大输出。
	 *  
	 */
	@Test
	public void test4() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入三个数：");
		int []array = new int[3];
		for(int i = 0; i < array.length ;i ++) {  //输入的数转化为数组
			int a = scanner.nextInt();
			array[i] = a;
		}
		System.out.print("输入的三个数是：");       //打印输入的三个数
		for(int i = 0; i <array.length; i++) {
			System.out.print(array[i] + " ");
		}
		int temp = 0;
		for(int i = 0;i < array.length; i++) {
			for(int j = 0; j < array.length - 1 -i; j++) {
				if(array[j] > array [j + 1]) {
					temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		System.out.print("三个数从小到大输出为：");
		for(int i = 0;i < array.length; i++) {
			System.out.print(array[i] + " ");
		}
	}
}	
	
